#!/usr/bin/py.valthon
# vim: set fileencoding=utf-8 :
# Abstract Integer class.

class aInt (object):
    """Class Abstract Integer
    """
    def __init__(self, p1 = 0) :
        """ To instance x = aInt(p) where p ∈ Z and x ∈ aInt.
        pre: 'p1' is int.
        post: 'val' is int.
        param: 'self' instance.
        'p1' as int.
        return: null.
        """
        self.val = p1

    def __call__(self) :
        """ To use in the way.val x() returning an aInt.
        pre: 'val' is initialized.
        post: none.
        param: 'self' instance.
        return: 'val' as aInt.
        """
        return aInt(self.val)

    def is_integer(self) :
        """ Check whether x ∈ Z or not.
        pre: 'val' is initialized.
        post: none.
        param: 'self' instance.
        return:
        """
        return (self.val == int(self.val))

    def __abs__(self) :
        """x.__abs__() <==> abs(x)
        pre: 'val' is initialized.
        'val' is int.
        post: none.
        param: 'self' instance.
        return:
        """
        if self.val < 0 :
            return aInt(-self.val)
        else :
            return aInt(self.val)

    def __add__(self, y) :
        """x.__add__(y.val) <==> x+y
        pre: 'val' is initialized.
        'y' is either int or aInt.
        post: none.
        param: 'self' instance.
        'y' second operand.
        return:
        """
        return aInt(self.val + y)

    def __and__(self, y) :
        """x.__and__(y.val) <==> x&y
        pre: 'val' is initialized.
        'y' is either int or aInt.
        post: none.
        param: 'self' instance.
        'y' second operand.
        return:
        """
        return aInt(self.val & y)

    def __cmp__(self, y) :
        """x.__cmp__(y.val) <==> cmp(x,y)
        pre: 'val' is initialized.
        'y' is either int or aInt.
        post: none.
        param: 'self' instance.
        'y' second operand.
        return:
        """
        return aInt(self.val - y)

    def __coerce__(self, y) :
        """x.__coerce__(y.val) <==> coerce(x, y)
        pre: 'val' is initialized.
        'y' is either int.
        post: none.
        param: 'self' instance.
        'y' second operand.
        return:
        """
        return (aInt(self.val), aInt(y))

    def __div__(self, y) :
        """x.__div__(y.val) <==> x/y
        pre: 'val' is initialized.
        'y' is either int or aInt.
        post: none.
        param: 'self' instance.
        'y' second operand.
        return:
        """
        return aInt(self.val / y)

    def __divmod__(self, y) :
        """x.__divmod__(y.val) <==> divmod(x, y)
        pre: 'val' is initialized.
        'y' is either int or aInt.
        post: none.
        param: 'self' instance.
        'y' second operand.
        return:
        """
        x = self.val
        return (aInt((x - x % y) / y), aInt(x % y))

    def __float__(self) :
        """x.__float__() <==> float(x)
        pre: 'val' is initialized.
        post: none.
        param: 'self' instance.
        return:
        """
        return 1.0 * self.val

    def __floordiv__(self, y) :
        """x.__floordiv__(y.val) <==> x//y
        pre: 'val' is initialized.
        'y' is either int or aInt.
        post: none.
        param: 'self' instance.
        'y' second operand.
        return:
        """
        return aInt(self.val // y)

    def __getattribute__(self, key):
        """x.__getattribute__('name') <==> x.name
        Emulate type_getattro() in Objects/typeobject.c
        pre:
        post:
        param:
        return:
        """
        v = object.__getattribute__(self, key)
        if hasattr(v, '__get__'):
            return v.__get__(None, self)
        return v

    def __hex__(self) :
        """x.__hex__() <==> hex(x)
        pre: 'val' is initialized.
        post: none.
        param: 'self' instance.
        return:
        """
        return hex(self.val)

    def __int__(self) :
        """x.__int__() <==> int(x)
        pre: 'val' is initialized.
        post: none.
        param: 'self' instance.
        return:
        """
        return int(self.val)

    def __invert__(self) :
        """x.__invert__() <==> ~x
        pre: 'val' is initialized.
        post: none.
        param: 'self' instance.
        return:
        """
        return aInt(~self.val)

    def __long__(self) :
        """x.__long__() <==> long(x)
        pre: 'val' is initialized.
        post: none.
        param: 'self' instance.
        return:
        """
        return long(self.val)

    def __lshift__(self, y) :
        """x.__lshift__(y.val) <==> x<<y
        pre: 'val' is initialized.
        'y' is either int or aInt.
        post: none.
        param: 'self' instance.
        'y' second operand.
        return:
        """
        return aInt(self.val << y)

    def __mod__(self, y) :
        """x.__mod__(y.val) <==> x%y
        pre: 'val' is initialized.
        'y' is either int or aInt.
        post: none.
        param: 'self' instance.
        'y' second operand.
        return:
        """
        return aInt(self.val % y)

    def __mul__(self, y) :
        """x.__mul__(y.val) <==> x*y
        pre: 'val' is initialized.
        'y' is either int or aInt.
        post: none.
        param: 'self' instance.
        'y' second operand.
        return:
        """
        return aInt(self.val * y)

    def __neg__(self) :
        """x.__neg__() <==> -x
        pre: 'val' is initialized.
        post: none.
        param: 'self' instance.
        return:
        """
        return aInt(-self.val)

    def __oct__(self) :
        """x.__oct__() <==> oct(x)
        pre: 'val' is initialized.
        post: none.
        param: 'self' instance.
        return:
        """
        return oct(self.val)

    def __or__(self, y) :
        """x.__or__(y.val) <==> x|y
        pre: 'val' is initialized.
        'y' is either int or aInt.
        post: none.
        param: 'self' instance.
        'y' second operand.
        return:
        """
        return aInt(self.val | y)

    def __pos__(self) :
        """x.__pos__() <==> +x
        pre: 'val' is initialized.
        post: none.
        param: 'self' instance.
        return:
        """
        return aInt(+self.val)

    def __pow__(self, y) :
        """x.__pow__(y.val[, z]) <==> pow(x, y[, z])
        pre: 'val' is initialized.
        'y' is either int or aInt.
        post: none.
        param: 'self' instance.
        'y' second operand.
        return:
        """
        return aInt(pow(self.val, y))

    def __radd__(self, y) :
        """x.__radd__(y.val) <==> y+x
        pre: 'val' is initialized.
        'y' is either int or aInt.
        post: none.
        param: 'self' instance.
        'y' second operand.
        return:
        """
        return aInt(y + self.val)

    def __rand__(self, y) :
        """x.__rand__(y.val) <==> y&x
        pre: 'val' is initialized.
        'y' is either int or aInt.
        post: none.
        param: 'self' instance.
        'y' second operand.
        return:
        """
        return aInt(y & self.val)

    def __rdiv__(self, y) :
        """x.__rdiv__(y.val) <==> y/x
        pre: 'val' is initialized.
        'y' is either int or aInt.
        post: none.
        param: 'self' instance.
        'y' second operand.
        return:
        """
        return aInt(y / self.val)

    def __repr__(self) :
        """x.__repr__() <==> repr(x)
        pre: 'val' is initialized.
        post: none.
        param: 'self' instance.
        return:
        """
        return repr(self.val)

    def __rfloordiv__(self, y) :
        """x.__rfloordiv__(y.val) <==> y//x
        pre: 'val' is initialized.
        'y' is either int or aInt.
        post: none.
        param: 'self' instance.
        'y' second operand.
        return:
        """
        return aInt(y // self.val)

    def __rlshift__(self, y) :
        """x.__rlshift__(y.val) <==> y<<x
        pre: 'val' is initialized.
        'y' is either int or aInt.
        post: none.
        param: 'self' instance.
        'y' second operand.
        return:
        """
        return aInt(y << self.val)

    def __rmod__(self, y) :
        """x.__rmod__(y.val) <==> y%x
        pre: 'val' is initialized.
        'y' is either int or aInt.
        'y' is either int or aInt.
        post: none.
        param: 'self' instance.
        'y' second operand.
        return:
        """
        return aInt(y % self.val)

    def __rmul__(self, y) :
        """x.__rmul__(y.val) <==> y*x
        pre: 'val' is initialized.
        'y' is either int or aInt.
        post: none.
        param: 'self' instance.
        'y' second operand.
        return:
        """
        return aInt(y * self.val)

    def __ror__(self, y) :
        """x.__ror__(y.val) <==> y|x
        pre: 'val' is initialized.
        'y' is either int or aInt.
        post: none.
        param: 'self' instance.
        'y' second operand.
        return:
        """
        return aInt(y | self.val)

    def __rpow__(self, y) :
        """y.val.__rpow__(x[, z]) <==> rpow(x, y[, z])
        pre: 'val' is initialized.
        'y' is either int or aInt.
        post: none.
        param: 'self' instance.
        'y' second operand.
        return:
        """
        return aInt(pow(y, self.val))

    def __rrshift__(self, y) :
        """x.__rrshift__(y.val) <==> y>>x
        pre: 'val' is initialized.
        'y' is either int or aInt.
        post: none.
        param: 'self' instance.
        'y' second operand.
        return:
        """
        return aInt(y >> self.val)

    def __rshift__(self, y) :
        """x.__rshift__(y.val) <==> x>>y
        pre: 'val' is initialized.
        'y' is either int or aInt.
        post: none.
        param: 'self' instance.
        'y' second operand.
        return:
        """
        return aInt(self.val >> y)

    def __rsub__(self, y) :
        """x.__rsub__(y.val) <==> y-x
        pre: 'val' is initialized.
        'y' is either int or aInt.
        post: none.
        param: 'self' instance.
        'y' second operand.
        return:
        """
        return aInt(y - self.val)

    def __rxor__(self, y) :
        """x.__rxor__(y.val) <==> y^x
        pre: 'val' is initialized.
        'y' is either int or aInt.
        post: none.
        param: 'self' instance.
        'y' second operand.
        return:
        """
        return aInt(y ^ self.val)

    def __str__(self) :
        """x.__str__() <==> str(x)
        pre: 'val' is initialized.
        post: none.
        param: 'self' instance.
        return:
        """
        return str(self.val)

    def __sub__(self, y) :
        """x.__sub__(y.val) <==> x-y
        pre: 'val' is initialized.
        'y' is either int or aInt.
        post: none.
        param: 'self' instance.
        'y' second operand.
        return:
        """
        return aInt(self.val - y)

    def __xor__(self, y) :
        """x.__xor__(y.val) <==> x^y
        pre: 'val' is initialized.
        'y' is either int or aInt.
        post: none.
        param: 'self' instance.
        'y' second operand.
        return:
        """
        return aInt(self.val ^ y)

